<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户产品管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/user/hkUserProduct/">用户产品列表</a></li>
		<li class="active"><a href="${ctx}/sys/user/hkUserProduct/form?id=${hkUserProduct.id}">用户产品<shiro:hasPermission name="sys:user:hkUserProduct:edit">${not empty hkUserProduct.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:user:hkUserProduct:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="hkUserProduct" action="${ctx}/sys/user/hkUserProduct/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">用户id：</label>
			<div class="controls">

				<sys:tableSelect id="user" name="user.id" value="${hkUserProduct.user.id}" labelName="user.name" labelValue="${hkUserProduct.user.name}" title="选择用户" url="${ctx}/sys/user/hkUser/list?1=1" checked="1"   />

			</div>
		</div>
		<div class="control-group">
			<label class="control-label">标题：</label>
			<div class="controls">
				<form:input path="title" htmlEscape="false" maxlength="100" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">子标题：</label>
			<div class="controls">
				<form:input path="subtitle" htmlEscape="false" maxlength="100" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">图片：</label>
			<div class="controls">
				<form:hidden id="imgSrc" path="imgSrc" htmlEscape="false" maxlength="200" class="input-xlarge"/>
				<sys:ckfinder input="imgSrc" type="images" uploadPath="/hkUserProductImg" selectMultiple="false"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">序号：</label>
			<div class="controls">
				<form:input path="rank" htmlEscape="false" maxlength="200" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">单价：</label>
			<div class="controls">
				<form:input path="price" htmlEscape="false" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">数量：</label>
			<div class="controls">
				<form:input path="num" htmlEscape="false" maxlength="11" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">状态：</label>
			<div class="controls">
				<form:select path="state" class="input-xlarge ">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('hk_product_state')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">预约数：</label>
			<div class="controls">
				<form:input path="preordernum" htmlEscape="false" maxlength="11" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">购买数：</label>
			<div class="controls">
				<form:input path="ordernum" htmlEscape="false" maxlength="11" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">查看数：</label>
			<div class="controls">
				<form:input path="viewCount" htmlEscape="false" maxlength="11" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">运费：</label>
			<div class="controls">
				<form:input path="freightId" htmlEscape="false" maxlength="32" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">成交额：</label>
			<div class="controls">
				<form:input path="money" htmlEscape="false" maxlength="11" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">上架状态：</label>
			<div class="controls">
				<form:select path="isupper" class="input-xlarge ">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="100" class="input-xxlarge "/>
			</div>
		</div>
			<div class="control-group">
				<label class="control-label">用户产品分类：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th>分类</th>
								<th>备注</th>
								<shiro:hasPermission name="sys:user:hkUserProduct:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="hkUserProductCategoryList">
						</tbody>
						<shiro:hasPermission name="sys:user:hkUserProduct:edit"><tfoot>
							<tr><td colspan="4"><a href="javascript:" onclick="addRow('#hkUserProductCategoryList', hkUserProductCategoryRowIdx, hkUserProductCategoryTpl);hkUserProductCategoryRowIdx = hkUserProductCategoryRowIdx + 1;" class="btn">新增</a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="hkUserProductCategoryTpl">//<!--
						<tr id="hkUserProductCategoryList{{idx}}">
							<td class="hide">
								<input id="hkUserProductCategoryList{{idx}}_id" name="hkUserProductCategoryList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="hkUserProductCategoryList{{idx}}_delFlag" name="hkUserProductCategoryList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
								<sys:treeselect   id="hkUserProductCategoryList{{idx}}_category" name="hkUserProductCategoryList[{{idx}}].category.id"   labelName="category.name" labelValue="{{row.category.name}}" value="{{row.category.id}}"
										  title="分类" url="/media/hkMediaShopCategory/treeData"   cssClass="" allowClear="true"/>
							</td>
							<td>
								<textarea id="hkUserProductCategoryList{{idx}}_remarks" name="hkUserProductCategoryList[{{idx}}].remarks" rows="4" maxlength="100" class="input-small ">{{row.remarks}}</textarea>
							</td>
							<shiro:hasPermission name="sys:user:hkUserProduct:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#hkUserProductCategoryList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var hkUserProductCategoryRowIdx = 0, hkUserProductCategoryTpl = $("#hkUserProductCategoryTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(hkUserProduct.hkUserProductCategoryList)};
							for (var i=0; i<data.length; i++){
								addRow('#hkUserProductCategoryList', hkUserProductCategoryRowIdx, hkUserProductCategoryTpl, data[i]);
								hkUserProductCategoryRowIdx = hkUserProductCategoryRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">用户产品图片：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th>图片</th>
								<th>序号</th>
								<th>备注</th>
								<shiro:hasPermission name="sys:user:hkUserProduct:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="hkUserProductImgList">
						</tbody>
						<shiro:hasPermission name="sys:user:hkUserProduct:edit"><tfoot>
							<tr><td colspan="5"><a href="javascript:" onclick="addRow('#hkUserProductImgList', hkUserProductImgRowIdx, hkUserProductImgTpl);hkUserProductImgRowIdx = hkUserProductImgRowIdx + 1;" class="btn">新增</a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="hkUserProductImgTpl">//<!--
						<tr id="hkUserProductImgList{{idx}}">
							<td class="hide">
								<input id="hkUserProductImgList{{idx}}_id" name="hkUserProductImgList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="hkUserProductImgList{{idx}}_delFlag" name="hkUserProductImgList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
							<input id="hkUserProductImgList{{idx}}imgSrc" name="hkUserProductImgList[{{idx}}].imgSrc" type="hidden" value="{{row.imgSrc}}" maxlength="100"/>
								<sys:ckfinder input="hkUserProductImgList{{idx}}imgSrc" type="images" uploadPath="/hkUserProductImg" selectMultiple="false" maxWidth="60" maxHeight="60 "/>
							</td>
							<td>
								<input id="hkUserProductImgList{{idx}}_rank" name="hkUserProductImgList[{{idx}}].rank" type="text" value="{{row.rank}}" maxlength="11" class="input-small "/>
							</td>
							<td>
								<textarea id="hkUserProductImgList{{idx}}_remarks" name="hkUserProductImgList[{{idx}}].remarks" rows="4" maxlength="100" class="input-small ">{{row.remarks}}</textarea>
							</td>
							<shiro:hasPermission name="sys:user:hkUserProduct:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#hkUserProductImgList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var hkUserProductImgRowIdx = 0, hkUserProductImgTpl = $("#hkUserProductImgTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(hkUserProduct.hkUserProductImgList)};
							for (var i=0; i<data.length; i++){
								addRow('#hkUserProductImgList', hkUserProductImgRowIdx, hkUserProductImgTpl, data[i]);
								hkUserProductImgRowIdx = hkUserProductImgRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">用户产品型号：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th>型号</th>
								<th>价格</th>
								<th>库存</th>
								<th>备注</th>
								<shiro:hasPermission name="sys:user:hkUserProduct:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="hkUserProductSkuList">
						</tbody>
						<shiro:hasPermission name="sys:user:hkUserProduct:edit"><tfoot>
							<tr><td colspan="6"><a href="javascript:" onclick="addRow('#hkUserProductSkuList', hkUserProductSkuRowIdx, hkUserProductSkuTpl);hkUserProductSkuRowIdx = hkUserProductSkuRowIdx + 1;" class="btn">新增</a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="hkUserProductSkuTpl">//<!--
						<tr id="hkUserProductSkuList{{idx}}">
							<td class="hide">
								<input id="hkUserProductSkuList{{idx}}_id" name="hkUserProductSkuList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="hkUserProductSkuList{{idx}}_delFlag" name="hkUserProductSkuList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
								<input id="hkUserProductSkuList{{idx}}_model" name="hkUserProductSkuList[{{idx}}].model" type="text" value="{{row.model}}" maxlength="200" class="input-small "/>
							</td>
							<td>
								<input id="hkUserProductSkuList{{idx}}_price" name="hkUserProductSkuList[{{idx}}].price" type="text" value="{{row.price}}" class="input-small "/>
							</td>
							<td>
								<input id="hkUserProductSkuList{{idx}}_num" name="hkUserProductSkuList[{{idx}}].num" type="text" value="{{row.num}}" maxlength="11" class="input-small "/>
							</td>
							<td>
								<textarea id="hkUserProductSkuList{{idx}}_remarks" name="hkUserProductSkuList[{{idx}}].remarks" rows="4" maxlength="100" class="input-small ">{{row.remarks}}</textarea>
							</td>
							<shiro:hasPermission name="sys:user:hkUserProduct:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#hkUserProductSkuList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var hkUserProductSkuRowIdx = 0, hkUserProductSkuTpl = $("#hkUserProductSkuTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(hkUserProduct.hkUserProductSkuList)};
							for (var i=0; i<data.length; i++){
								addRow('#hkUserProductSkuList', hkUserProductSkuRowIdx, hkUserProductSkuTpl, data[i]);
								hkUserProductSkuRowIdx = hkUserProductSkuRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>
		<div class="form-actions">
			<shiro:hasPermission name="sys:user:hkUserProduct:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>